package com.base.myproject.client.HR.attendance;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Label;
/**
 *请假单
 * @author Administrator
 * datebable: hr_takeLeave
 */
public class TakeLeave extends BaseJDBCPanel{
	public TakeLeave() {
		// TODO Auto-generated constructor stub
		init();
	}
	public void init() {
    	//initTreePanel();
    	initWeigetx();	
    	//registerMainStore(store);
		//registerStore(store);
	}
    public void complete()
	{
		super.complete();
	}
	private void initWeigetx(){
		VerticalPanel vp=new VerticalPanel();
		vp.add(getBaseGrid());
		vp.add(getBaseFormPanel());
		add(vp);
	}
	
	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	BaseStore<BusiObject> createStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("signDate");
	type.getField("signDate").setType(Date.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("name");
	type.getField("name").setType(String.class);
	type.addField("department");
	type.getField("department").setType(String.class);
	type.addField("useDate");
	type.getField("useDate").setType(Date.class);
	type.addField("type");
	type.getField("type").setType(String.class);
	type.addField("Bgntime");
	type.getField("Bgntime").setType(Date.class);
	type.addField("Endtime");
	type.getField("Endtime").setType(Date.class);
	type.addField("status");
	type.getField("status").setType(String.class);
	type.addField("batchNo");
	type.getField("batchNo").setType(String.class);
	type.addField("period");
	type.getField("period").setType(Double.class);
	type.addField("C_period");
	type.getField("C_period").setType(Double.class);
	type.addField("remark");
	type.getField("remark").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_Attendance_takeLeave");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from hr_Attendance_takeLeave");
	 store = new BaseStore<BusiObject>(type, info);
	 return store;}
	
	BaseGridPanel grid=null;
	BaseGridPanel getBaseGrid() {
		if (grid == null) {
			createGrid();
		}
		return grid;
	}
   void createGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());

	ColumnConfig C2 = new ColumnConfig("signDate", "填表日期", 80);
	DateField dateField1 = new DateField();
	C2.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C2.setEditor(new CellEditor(dateField1));
	C2.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	columns.add(C2);
	
	ColumnConfig C3 = new ColumnConfig("bcode", "员工编号", 80);
	columns.add(C3);
	ColumnConfig C4 = new ColumnConfig("name", "申请人", 80);
	columns.add(C4);
	ColumnConfig C5 = new ColumnConfig("department", "部门名称", 80);
	columns.add(C5);
	
	ColumnConfig C6 = new ColumnConfig("useDate", "发生日期", 80);
	DateField dateField2 = new DateField();
	C6.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C6.setEditor(new CellEditor(dateField2));
	C6.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	columns.add(C6);
	
	ColumnConfig C7 = new ColumnConfig("type", "请假类型", 80);
	columns.add(C7);
	
	ColumnConfig C8 = new ColumnConfig("Bgntime", "起始时间", 80);
	DateField dateField3 = new DateField();
	C8.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C8.setEditor(new CellEditor(dateField3));
	C8.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	columns.add(C8);
	
	ColumnConfig C9 = new ColumnConfig("Endtime", "结束时间", 80);
	DateField dateField4 = new DateField();
	C9.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C9.setEditor(new CellEditor(dateField4));
	C9.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	columns.add(C9);
	
	ColumnConfig C10 = new ColumnConfig("status", "审批状态", 80);
	columns.add(C10);
	ColumnConfig C11 = new ColumnConfig("batchNo", "班次", 40);
	columns.add(C11);
	ColumnConfig C12 = new ColumnConfig("period", "时长", 40);
	columns.add(C12);
	ColumnConfig C13 = new ColumnConfig("C_period", "计算时长", 55);
	columns.add(C13);
	ColumnConfig C14 = new ColumnConfig("remark", "说明", 140);
	columns.add(C14);

	ColumnModel cm = new ColumnModel(columns);
	grid = new BaseGridPanel(getStore(), cm,true,true);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	grid.getBg().setHeight(235);
	grid.getBg().setWidth(820);
	grid.getBg().setSelectionModel(cbs);
	}
   
   BaseFormPanel form  =null;
   BaseFormPanel getBaseFormPanel() {
		if (form == null) {
			createForm();
		}
		return form;
	 }
	void createForm() {
		form = new BaseFormPanel(getStore());
		TableLayout tl = new TableLayout(8);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);
		form.setHeight(235);
		form.setWidth(820);
 
   form.add(new Label("填表日期:"),td);
    DateField C_data2  = new DateField(); 
    C_data2.setWidth(127);
   C_data2.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
   C_data2.setName("signDate");
   form.add(C_data2,td);
   form.add(new Label("员工编号:"),td);
   TextField<String> C_num3  = new TextField<String>(); 
   C_num3.setName("bcode");
   form.add(C_num3,td);
   form.add(new Label("申请人:"),td);
   TextField<String> C_num4  = new TextField<String>(); 
   C_num4.setName("name");
   form.add(C_num4,td);
   form.add(new Label("部门名称:"),td);
   TextField<String> C_num5  = new TextField<String>(); 
   C_num5.setName("department");
   form.add(C_num5,td);
   form.add(new Label("发生日期:"),td);
    DateField C_data6  = new DateField(); 
    C_data6.setWidth(127);
   C_data6.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
   C_data6.setName("useDate");
   form.add(C_data6,td);
   form.add(new Label("请假类型:"),td);
   TextField<String> C_num7  = new TextField<String>(); 
   C_num7.setName("type");
   form.add(C_num7,td);
   form.add(new Label("起始时间:"),td);
    DateField C_data8  = new DateField(); 
    C_data8.setWidth(127);
   C_data8.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
   C_data8.setName("Bgntime");
   form.add(C_data8,td);
   form.add(new Label("结束时间:"),td);
    DateField C_data9  = new DateField(); 
    C_data9.setWidth(127);
   C_data9.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
   C_data9.setName("Endtime");
   form.add(C_data9,td);
   form.add(new Label("审批状态:"),td);
   TextField<String> C_num10  = new TextField<String>(); 
   C_num10.setName("status");
   form.add(C_num10,td);
   form.add(new Label("班次:"),td);
   TextField<String> C_num11  = new TextField<String>(); 
   C_num11.setName("batchNo");
   form.add(C_num11,td);
   form.add(new Label("时长:"),td);
    NumberField C_num12  = new NumberField(); 
   C_num12.setPropertyEditorType(Double.class); 
   C_num12.setName("period");
   form.add(C_num12,td);
   form.add(new Label("计算时长:"),td);
    NumberField C_num13  = new NumberField(); 
   C_num13.setPropertyEditorType(Double.class); 
   C_num13.setName("C_period");
   form.add(C_num13,td);
   form.add(new Label("说明:"),td);
   TextField<String> C_num14  = new TextField<String>(); 
   C_num14.setName("remark");
   form.add(C_num14,td);
   form.inited(); 
   };
   
}
